import "dart:convert";

import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/pages/transfer_station.dart";
import "package:ct_pa_majordomo/pages/widgets/menu_block.dart";
import "package:ct_pa_majordomo/utils/stacker.dart";
import "package:ct_pa_majordomo/utils/storage.dart";
import "package:ct_pa_majordomo/widgets/button/index.dart";
import "package:ct_pa_majordomo/widgets/button/tap_text.dart";
import "package:ct_pa_majordomo/widgets/header.dart";
import "package:flutter/material.dart";

class Setting extends StatefulWidget {
  const Setting({super.key});


  @override
  State<StatefulWidget> createState() => _SettingState();
}

class _SettingState extends State<Setting> {

  final Map _user = jsonDecode(storage.getString("info") ?? "");

  Future<void> _logout(BuildContext context) async {
    storage.remove("token");
    storage.remove("apartment");
    storage.remove("info");
    Stacker.pushAndRemoveUntil(const TransferStation());
  }

  MenuBlockItem _renderSwitch(String text) => MenuBlockItem(
    showArrow: false,
    text: text,
    suffix: Switch(value: true, onChanged: (value) {}),
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const Header(title: Text("设置")),
      body: ListView(
        padding: const EdgeInsets.all(ThemeVars.paddingPage),
        children: [
          MenuBlock(
            items: [
              MenuBlockItem(text: "账号", suffix: Text("+${_user["phonenumber"]}")),
              // MenuBlockItem(text: "电子邮箱"),
              MenuBlockItem(
                text: "修改密码",
                onTap: () {
                  Stacker.pushNamed("/mine/modify-password");
                },
              ),
            ],
          ),
          // const SizedBox(height: 15),
          // MenuBlock(
          //   items: [
          //     _renderSwitch("提示音"),
          //     _renderSwitch("触摸开锁"),
          //     _renderSwitch("消息推送"),
          //     MenuBlockItem(text: "转移管理员"),
          //   ],
          // ),
          const SizedBox(height: 30),
          Button(
            type: ButtonType.danger,
            onPressed: () => _logout(context),
            child: const Text("退出登录"),
          ),
          // const SizedBox(height: 20),
          // Align(
          //   alignment: Alignment.centerRight,
          //   child: TapText(
          //     style: const TextStyle(color: ThemeVars.colorTextSec),
          //     text: "注销账号",
          //     onTap: () {},
          //   ),
          // ),
        ],
      ),
    );
  }

}
